package com.fg.pro.sys.controller;



import com.fg.pro.model.config.ValidationGroups;
import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.model.sys.entity.SysDept;
import com.fg.pro.sys.service.SysDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * 部门(SysDept)表控制层
 *
 * @author makejava
 * @since 2025-07-17 10:10:47
 */
@Tag(name = "SysDept",description = "部门")
@RestController
@RequestMapping("sysDept")
public class SysDeptController {
    /**
     * 服务对象
     */
    @Resource
    private SysDeptService sysDeptService;

    @Operation(summary = "获取部门树状",description = "")
    @GetMapping("/getTree")
    public ResponseResult getTree(){
        List<SysDept> deptList = sysDeptService.getTree();
        return ResponseResult.okResult(deptList);
    }

    @Operation(summary = "获取部门",description = "id")
    @GetMapping("/getById")
    public ResponseResult getById(@RequestParam String id){
        SysDept sysDept = sysDeptService.getById(id);
        return ResponseResult.okResult(sysDept);
    }

    @Operation(summary = "添加部门",description = "sysDept")
    @PutMapping("/save")
    public ResponseResult save(@RequestBody (required = true)@Validated(ValidationGroups.Insert.class)SysDept sysDept){
        boolean save = sysDeptService.save(sysDept);
        return ResponseResult.okResult(save?"添加成功":"添加失败");
    }

    @Operation(summary = "修改部门",description = "sysDept")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody (required = true)@Validated(ValidationGroups.Update.class)SysDept sysDept){
        boolean update = sysDeptService.updateById(sysDept);
        return ResponseResult.okResult(update?"修改成功":"修改失败");
    }

    @Operation(summary = "删除部门",description = "ids")
    @DeleteMapping("/del")
    public ResponseResult del(@RequestParam (required = true)Long[] ids){
        List<Long> list = Arrays.asList(ids);
        boolean del = sysDeptService.removeByIds(list);
        return ResponseResult.okResult(del?"删除成功":"删除失败");
    }

}

